import { loginIgnore } from '@/router/index'
import { checkAuthorization } from '@/utils/request'


/**
 * 登录守卫
 * @param to
 * @param form
 * @param next
 * @param options
 */
const loginGuard = (to, from, next, options) => {
  const { toast } = options
  if (!loginIgnore.includes(to) && !checkAuthorization()) {
    toast({
      message: '登录已失效，请重新登录',
      position: 'top',
    });
    next({ path: '/login' })
  } else {
    next()
  }
}

export default {
  beforeEach: [loginGuard],
  afterEach: []
}
